<!--  -->
<template>
  <div class="">
    <top-tit :tit="'我的邀请码'"></top-tit>
    <div class="promde_code_box">
      <div class="container">
        <div class="left">
          <div class="value" v-text="preomoCodeData.code">暂无</div>
          <div class="tit">我的邀请码</div>
          <div class="copy" @click="copy">复制</div>
        </div>
        <div class="right">
          <div class="value">
            <span>￥</span><span v-text="preomoCodeData.invited_user_reward"></span>
          </div>
          <div class="tit">邀请奖励金</div>
        </div>
      </div>
      <div class="content">
        <div class="con">
          <p>邀请者分享邀请链接给其他人下单成功后，将的到如下对应金额奖励：</p>
          <p>邀请人奖励: 0元</p>
          <p>被邀请人奖励: 0元</p>
          <p>订单抽成: 0%</p>
        </div>
      </div>
    </div>

    <div class="tab_top">
      <div class="container">
        <div class="tab_item" :class="{ active: tabIndex == 0 }" @click="changeTabIndex(0)">
          邀请记录
        </div>
        <div class="tab_item" :class="{ active: tabIndex == 1 }" @click="changeTabIndex(1)">
          资金明细
        </div>
        <div class="tab_item" :class="{ active: tabIndex == 2 }" @click="changeTabIndex(2)">
          提现明细
        </div>
      </div>
    </div>

    <div class="img_box">
      <div class="container">
        <img src="@/assets/img/onstudy-nologin.png" alt="" />
      </div>
    </div>
  </div>
</template>

<script>
//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
//例如：import 《组件名称》 from '《组件路径》';
import topTit from "@/components/topTit";
import { Toast } from "vant";
export default {
  name: "promoCode",
  //import引入的组件需要注入到对象中才能使用
  components: {
    topTit,
  },
  data() {
    //这里存放数据
    return {
      tabIndex: 0,
      preomoCodeData: [],
    };
  },
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {},
  //方法集合
  methods: {
    changeTabIndex(num) {
      this.tabIndex = num;
    },
    copy() {
      let elInput = document.createElement("input");
      elInput.value = this.preomoCodeData.code;
      // document.body.appendChild(elInput);
      // 选择对象
      elInput.select();
      // console.log(elInput, elInput.value);
      // 执行浏览器复制命令
      // console.log("复制成功");
      document.execCommand("Copy");
      elInput.remove();
      Toast.success("复制成功");
    },
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  async created() {
    await this.$axios.get("http://1.14.239.98/api/v2/member/promoCode").then((res) => {
      // console.log(res);
      this.preomoCodeData = res.data;
      // console.log(this.preomoCodeData);
    });
  },
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {},
  beforeCreate() {}, //生命周期 - 创建之前
  beforeMount() {}, //生命周期 - 挂载之前
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  activated() {}, //如果页面有keep-alive缓存功能，这个函数会触发
};
</script>
<style scoped lang="less">
div.promde_code_box {
  padding: 30px 15px 20px;
  background-color: #1784ed;
  div.container {
    width: 6.9rem;
    background: linear-gradient(180deg, #fff6cf, #ffeaa1);
    border-radius: 4px;
    display: flex;
    padding: 0 0.2rem;
    padding-top: 0.2rem;
    margin-bottom: 20px;
    div.left {
      flex-basis: 50%;
      display: flex;
      flex-direction: column;
      div.value {
        font-size: 0.4rem;
        color: #333;
        height: 1rem;
        line-height: 1rem;
      }

      div.tit {
        font-size: 0.26rem;
        color: #666;
        // height: 1rem;
        font-weight: 500;
      }
      div.copy {
        width: 1.92rem;
        height: 0.6rem;
        border-radius: 0.3rem;
        border: 1px solid #1784ed;
        cursor: pointer;
        // margin-top: 20px;
        font-size: 0.28rem;
        font-weight: 400;
        color: #1784ed;
        margin: 0.4rem auto;
        line-height: 0.6rem;
        // display: flex;
        // align-items: center;
        // justify-content: center;
        // margin-left: 50px;
      }
    }

    div.right {
      flex-basis: 50%;
      display: flex;
      flex-direction: column;
      div.value {
        height: 1rem;
        line-height: 1rem;
        font-size: 0.4rem;
        color: #333;
      }

      div.tit {
        // height: 1rem;
        font-size: 0.26rem;
        color: #666;
        font-weight: 500;
      }
    }
    
  }
  div.content { 
    width: 100%;
      div.con {
        width: 6.9rem;
        margin: 0 auto;
        display: flex;
        flex-direction: column;
        background-color: none;
        color: white;
        p {
            margin-bottom: .16rem;
            text-align: start;
            font-size: .26rem;
        }
      }
    }
}

div.tab_top {
  height: 1.2rem;
  width: 100%;
  box-sizing: content-box;
  .container {
    height: 1.2rem;
    width: 6.9rem;
    display: flex;
    justify-content: space-around;
    align-items: center;
    div.tab_item {
      height: 1.2rem;
      font-size: 0.32rem;
      color: #666;
      line-height: 1.2rem;
      //   margin-right: 0.32rem;
    }
    div.tab_item.active {
      color: #3ca7fa;
      font-weight: bold;
    }
  }
}

div.img_box {
  div.container {
    padding: 50px 0;
    img {
      width: 2.4rem;
      height: 2.4rem;
    }
  }
}
</style>
